/*
 * main.c
 *
 *  Created on: 24.2.2012
 *      Author: lukas
 */
#include <avr/io.h>
#include <util/delay.h>
#include "servo.h"
#include "simpleUART.h"
#include "motor.h"

#define UART_BAUD_RATE 25
#define APPLY_SERVO_BOUNDARIES 1

int main() {
	PORTA &= ~(1 << PINA0);
	DDRA = 1 << PINA0;

	UARTInit(UART_BAUD_RATE);
	initServo(APPLY_SERVO_BOUNDARIES);
	MotorInit();

	MotorSetSpeed(30, 0);
	_delay_ms(3000);
	MotorSetSpeed(0, 1);
	_delay_ms(3000);
	MotorSetSpeed(255, 0);
	_delay_ms(3000);
	MotorSetSpeed(128, 1);

	while (1) {
		char data = UARTReadChar();
		positionServo(data);
		UARTWriteChar('(');
		UARTWriteChar(getCurrentServoPosition());
		UARTWriteChar(')');
		PORTA = ~PORTA;
	}

	return 0;
}


